home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 682 / rexxhostlib / rexxhost.doc < prev    next >
Text File  |  1995-03-18  |  19KB  |  433 lines

  1. ====================== RexxHost.Library v37.1 ========================
  2. ======================================================================
  3. An Amiga shared library for creating/managing ARexx host environments.
  4. ======================================================================
  5.  
  6. ========================== IMPORTANT NOTICE ==========================
  7. ======================================================================
  8. This is the official new release of rexxhost.library.  Due to register
  9. rearrangements  programs compiled using the old 1.6 release have to be
  10. recompiled  or  serious  system  crashes  will  result!  Note that the
  11. supplied library code can only be recompiled under Aztec 'C' 5.0.
  12.  
  13. ============================= Background =============================
  14. ======================================================================
  15. A  friend  of mine was busy developing a stock management program when
  16. he suddenly realized that an ARexx interface would be the only feature
  17. that wasn't already part of his project.  So he started to analyze, to
  18. program,  to  try - just to find out that it would be too much work to
  19. add it.
  20.         Some  months later a programmer who works for the same company
  21. I  am  working  for decided to rewrite his home-brewn assembler/linker
  22. program  to  interface to CygnusEd Professional.  The problem is:  his
  23. program  is written in assembly language, the standard host management
  24. routines are written in 'C'...
  25.         To  simplify  the host creation/management procedure I decided
  26. to  put  the  required  routines  and  some  extra  code into a shared
  27. library,  easy  to  use  by  ANY  language (can you imagine AmigaBASIC
  28. controlling AmigaTeX?).
  29.         As  soon  as the Aztec 'C' 5.0 update came in, the library has
  30. been  updated  to  take  advantage  of  the  new compiler features.  I
  31. suppose  the  source  code  can  be  seen  as  a  real  'treasure' for
  32. programmers  who also wish to build shared libraries with the new Manx
  33. compiler but find the original Manx support code a bit too confusing.
  34.  
  35. ============================= How to use =============================
  36. ======================================================================
  37. The  rexxhost.library needs ARexx (any version will do, v1.10 is best)
  38. to  work properly.  It needs to be opened EXPLICITELY, i.e.  it is not
  39. forced  into  memory by the ARexx server and CANNOT be loaded with the
  40. ADDLIB() call in rexx-scriptfiles.  An unlimited number of callers may
  41. open   the   library,   it   is   100%   reentrant.    Just  like  the
  42. rexxsyslib.library   the   rexxhost.library   stays  in  memory  until
  43. explicitely expunged (e.g.  via "flushlibs" call from Workbench).
  44.         The  OpenLibrary()  call  returns  a pointer to a RexxHostBase
  45. structure (as defined in the rexxhostbase.h include file).  It has the
  46. following format:
  47.  
  48.                 struct RexxHostBase
  49.                 {
  50.                         struct Library   LibNode;
  51.                         struct RxsLib   *RexxSysBase;
  52.                 };
  53.  
  54. The  pointer  to the RxsLib structure represents a pointer to the base
  55. of  rexxsyslib.library.   It  can  be  copied  by the calling process,
  56. rexxsyslib.library does not need to be opened explicitely.
  57.         All library functions are "bullet proof", i.e. if the supplied
  58. arguments  are  illegal  the  functions return immediately.  Note that
  59. this  library  only  contains  basic support functions, you will still
  60. have  to  do  command analysis, parsing and command processing on your
  61. own (which isn't difficult, look at the DClockHandler.c sourcecode for
  62. an example).
  63.  
  64. ============================= Compiling ==============================
  65. ======================================================================
  66. A  Makefile  for  Aztec  'C'  5.0 is supplied.  This version CANNOT be
  67. recompiled under compiler versions previous to 5.0.  Note that line 67
  68. in the ARexx 'C' include file 'rxslib.h' has to be changed from:
  69.  
  70.         WORD rl_NumMsg; /* pending count */
  71.  
  72. to:
  73.  
  74.         WORD rl_PgmMsg; /* pending count */
  75.  
  76. or  you  will  get  a 'multiple entry' message from the compiler (Bill
  77. obviously overlooked the misspelled entry).  In order to recompile the
  78. library the following symbol must be defined in your header files:
  79.  
  80.         #define AG_CloseLib     0x00090000
  81.  
  82. The  linker  requires  a  library  which  contains  glue codes for all
  83. rexxsyslib.library routines (rexx.lib).
  84.  
  85. ===================== RexxHost.Library Functions =====================
  86. ======================================================================
  87.  
  88. CreateRexxHost - Create a RexxHost with supplied name
  89.  
  90. Usage:
  91. RexxHost = CreateRexxHost(HostName)
  92.   D0                         A0
  93.  
  94. This  function  tries  to  allocate a public messageport with a unique
  95. name.   If  a  port  with the supplied name does already exist NULL is
  96. returned.   The  name of the HostPort to be created is copied so there
  97. is  no  need  to  keep  it  statically initialized in you application.
  98. Note:   NEVER use this function if you only want to allocate a general
  99. purpose  MsgPort.   Some  additional  type  checking  is  done in this
  100. routine.   A  RexxHost  is  an  extended  MsgPort  structure with some
  101. additional  data  which allows all library functions to test if a host
  102. address  is valid.  You should rather see a RexxHost as a MsgPort.  Do
  103. not  rely  on  the  existence  of  the  flags  following  the  MsgPort
  104. structure.
  105.  
  106.  
  107. DeleteRexxHost - Remove RexxHost
  108.  
  109. Usage:
  110. NULL = DeleteRexxHost(RexxHost)
  111.  D0              A0
  112.  
  113. A  supplied  RexxHost  is  removed  from the system, freeing allocated
  114. signals  and  nodes.  A NULL-pointer is always returned so user can do
  115. 'Host  =  DeleteRexxHost(Host);'.  Never use this function to remove a
  116. general   purpose   MsgPort  from  the  system  list,  in  which  case
  117. DeleteRexxHost()  is  guaranteed  to  return immediately without doing
  118. anything.
  119.  
  120.  
  121. SendRexxCommand() - Send a command to the rexx server
  122.  
  123. Usage:
  124. Success = SendRexxCommand(RexxHost,CommandString,FileExtension,HostName)
  125.   D0                         A0          A1             A2        A3
  126.  
  127. This  function  causes  the  rexx  server  to  execute  a script file.
  128. HostPort  must  point  to the host RexxHost, CommandString points to a
  129. string   containing   the   name   of  the  command  to  be  executed.
  130. FileExtension   and   HostName   are   optional   and   may  be  NULL.
  131. FileExtension  defines  the  script  file name extension for this host
  132. (for  standard rexx scripts this is ".rexx", for CygnusEd Professional
  133. it  is  ".ced").   HostName  is  supplied to allow the host to address
  134. different  sub-hosts, such as different windows a text editor may have
  135. open.  This function returns FALSE (= 0) if the command cannot be sent
  136. (rexx  may  not  be  running)  and  TRUE (= 1) if the message has been
  137. posted.
  138.  
  139.  
  140. FreeRexxCommand() - Free the contents of a RexxMsg
  141.  
  142. Usage:
  143. FreeRexxCommand(RexxMessage)
  144.                     A0
  145.  
  146. Having  successfully  called  SendRexxCommand()  the  rexx server will
  147. return the RexxMsg with result flags set.  This kind of message cannot
  148. be  replied (since it already has been replied by the rexx server) but
  149. has  to  be  deallocated.   Be  sure  to examine the result code flags
  150. before you remove the RexxMsg.
  151.  
  152.  
  153. ReplyRexxCommand() - Returns a RexxMsg to the rexx server
  154.  
  155. Usage:
  156. ReplyRexxCommand(RexxMessage,Primary,Secondary,Result)
  157.                      A0         D0      D1       A1
  158.  
  159. Having received a command from the rexx server the host has to process
  160. it.  After that the RexxMsg has to be replied so the rexx server knows
  161. about  the  result.  Primary and Secondary are the values to be passed
  162. in  the  result flags of the RexxMsg structure, Result is optional and
  163. may  be  NULL.   It  usually  points to a string containing the result
  164. (numeric or string) of the command having been executed.
  165.  
  166.  
  167. GetRexxCommand() - Get the first argument from a RexxMsg
  168.  
  169. Usage:
  170. String = GetRexxCommand(RexxMessage)
  171.   D0                        A0
  172.  
  173. This  function  is  supported to save the calling program from dealing
  174. with  pointer  offsets  (which  may  be  difficult  with some language
  175. implementations).  It returns a pointer to the first argument entry in
  176. the  supplied  RexxMsg  structure.   This  is  usually a command to be
  177. executed by the host.  If NULL is returned then the RexxMsg is a reply
  178. to a former SendRexxCommand() command.
  179.  
  180.  
  181. GetRexxArg() - Get the first argument from a RexxMsg
  182.  
  183. Usage:
  184. String = GetRexxArg(RexxMessage)
  185.   D0                    A0
  186.  
  187. This  function  is  supported to save the calling program from dealing
  188. with  pointer  offsets  (which  may  be  difficult  with some language
  189. implementations).  It returns a pointer to the first argument entry in
  190. the  supplied RexxMsg structure.  This function is almost identical to
  191. GetRexxCommand(),  the  string  pointer is always returned, no RexxMsg
  192. type consideration is done.
  193.  
  194.  
  195. GetRexxResult1() - Get the first RexxMsg result code
  196.  
  197. Usage:
  198. Result = GetRexxResult1(RexxMessage)
  199.   D0                        A0
  200.  
  201. This  function  is  supported to save the calling program from dealing
  202. with  pointer  offsets  (which  may  be  difficult  with some language
  203. implementations).  It returns the value of the first result code entry
  204. in the supplied RexxMsg structure.
  205.  
  206.  
  207. GetRexxResult2() - Get the second RexxMsg result code
  208.  
  209. Usage:
  210. Result = GetRexxResult2(RexxMessage)
  211.   D0                        A0
  212.  
  213. This  function  is  supported to save the calling program from dealing
  214. with  pointer  offsets  (which  may  be  difficult  with some language
  215. implementations).   It  returns  the  value  of the second result code
  216. entry in the supplied RexxMsg structure.
  217.  
  218.  
  219. GetToken() - Get the next argument from a string
  220.  
  221. Usage:
  222. Argument = GetToken(String,StartChar,AuxBuff,MaxLength)
  223.    D0                 A0      A1       A2       D0
  224.  
  225. GetToken()  implements easy argument parsing.  ARexx posts commands as
  226. NULL-terminated   strings   with   arguments   separated   by  spaces.
  227. GetToken()  takes  a pointer to the command string (String), a pointer
  228. to  a  counter  variable  (StartChar,  must be a long), a pointer to a
  229. buffer the next argument will be copied to (AuxBuff) and the length of
  230. the  buffer  the  next  argument  will  be copied to (MaxLength).  The
  231. result  will be a pointer to AuxBuff if an argument was found, NULL if
  232. the  end of the command string was reached.  You are to make sure that
  233. the string pointed to by AuxBuff is long enough to hold the arguments.
  234.  
  235.  
  236. GetStringValue() - Return the numeric value of a string
  237.  
  238. Usage:
  239. Value = GetStringValue(String)
  240.   D0                     A0
  241.  
  242. Just  like the 'C' language atoi() function GetStringValue() evaluates
  243. the contents of a string.  Its value is returned as a long word.  This
  244. function  helps  to  analyze  the contents of a RexxMsg result code or
  245. command argument.
  246.  
  247.  
  248. BuildValueString() - Turns a numeric value into a string
  249.  
  250. Usage:
  251. String = BuildValueString(Value,String)
  252.   D0                        D0    A0
  253.  
  254. This  function helps to build a string from a numeric value, just like
  255. the  'C'  language  itoa() function.  The supplied string must be long
  256. enough  to  hold  the digits built from Value.  A pointer to the built
  257. string is returned.
  258.  
  259.  
  260. RexxStrCmp() - Compare two strings ignoring case
  261.  
  262. Usage:
  263. Match = RexxStrCmp(String1,String2)
  264.   D0                 A0      A1
  265.  
  266. This  function  is  intended  to be a replacement for the 'C' function
  267. strcmp().   Other than the builtin strcmp, RexxStrCmp ignores the case
  268. of  both  strings  and even handles international characters correctly
  269. (i.e.   RexxStrCmp("äöüß","ÄÖÜß")  == 0).  The value returned as Match
  270. is  0  if both strings are considered equal, any other value indicates
  271. that both strings are different.
  272.  
  273.  
  274. GetRexxMsg() - Get a RexxMessage from a RexxHost
  275.  
  276. Usage:
  277. RexxMsg = GetRexxMsg(RexxHost,WaitForIt)
  278.    D0                   A0        D0
  279.  
  280. Use  this  function rather than calling GetMsg, since it does RexxHost
  281. type  checking.   As  a  special option, it will wait for a message to
  282. arrive  if  none  is  present  yet.   RexxHost  must  point to a valid
  283. RexxHost  MsgPort structure, WaitForIt must be FALSE (= 0) if you want
  284. this  function  to  return  immediately  if  there are no RexxMessages
  285. pending, TRUE if otherwise.
  286.  
  287.  
  288. SendRexxMsg() - Send a command to a Rexx host
  289.  
  290. Usage:
  291. Result = SendRexxMsg(HostName,MsgList,SingleMsg,GetResult)
  292.   D0                    A0      A1       A2        D0
  293.  
  294. Programs who wish to communicate directly with a Rexx host rather than
  295. posting  lots  of scriptfiles call this function.  HostName must point
  296. to  null  terminated  string  describing  the name of the Rexx host to
  297. receive  the  command,  MsgList  points to an array of null terminated
  298. strings,  SingleMsg points to a null terminated string.  Note:  Either
  299. MsgList  or  SingleMsg  must  be NULL.  The MsgList is copied directly
  300. into the 16 argument vectors of a RexxMsg.  SingleMsg will be put into
  301. argument  vector  zero.  Set GetResult to TRUE if you want a result to
  302. be  returned.   Note  that this function works synchronously and waits
  303. until the reply to the message arrives.
  304.  
  305.  
  306. GetRexxString() - Obtain and deallocate a result string
  307.  
  308. Usage:
  309. GetRexxString(ResultString,DestString)
  310.                    A0          A1
  311.  
  312. The  secondary  result code returned in a RexxMsg can be a string or a
  313. number.  To save system memory the string has to be deallocated.  This
  314. function  performs  two  actions for you:  it copies the result string
  315. into a supplied buffer and deallocates the original string afterwards.
  316. Note:   make sure the result you pass this function is really a string
  317. and  not  a number or you will deallocate innocent memory.  ATTENTION!
  318. There  is a very good chance that non-standard result strings (such as
  319. returned  by CygnusEd Professional 2.xx) cannot be deallocated by this
  320. function.   CEDPro2.xx does not use the standard RexxArg structure for
  321. string  results, but stores the length of the string being returned in
  322. the  first  longword  in front of the first character.  Sometimes this
  323. string is not even null-terminated!
  324.  
  325.  
  326. GetRexxClip() - Find a Rexx clip by name and return one argument
  327.  
  328. Usage:
  329. ArgX = GetRexxClip(Name,WhichArg)
  330.  D0                 A0     D0
  331.  
  332. The  rexx clip list is searched for a rexx resource node.  Returned is
  333. either  Arg1  or  Arg2 depending on the value you pass as WhichArg:  a
  334. value of 0 will return Arg1, 1 returns Arg2.
  335.  
  336. ============================== Nuisance ==============================
  337. ======================================================================
  338. The library could be shorter if the  Aztec 'C' linker  'LN'  generated
  339. proper hunks:
  340.  
  341. 1) DATA  and  BSS hunks are intermixed; as a result the BSS hunk turns
  342.    out to have length zero which will still force DOS to allocate four
  343.    extra bytes which are never used.
  344.  
  345. 2) Additionally  the  DATA/BSS  hunk has to be zeroed 'manually' which
  346.    requires some extra code in crt0.a68.
  347.  
  348. 3) Even  if  you  don't  request a BSS hunk the linker still generates
  349.    one.    The  -  empty  -  hunk  (including  superfluous  relocation
  350.    information) occupies disk space it doesn't need.
  351.  
  352.        Is there any chance this 'kludging' will ever be fixed?
  353.  
  354. ============================== Credits ===============================
  355. ======================================================================
  356. rexxhost.library  was  built  from example source code written by Gary
  357. Samad  &  Bill  Hawes (fancydemo.c), extensions & additional functions
  358. were created by Olaf 'Olsen' Barthel.
  359.    The  entire  contents  of  this library package may be used for any
  360. purpose,  no  regard  whether commercial or non-commercial.  No credit
  361. must  be  given  to  the  creator, nor must a registration fee be paid
  362. (though I wouldn't mind if anybody did).
  363.  
  364.                      THIS IS TRULY PUBLIC DOMAIN!
  365.  
  366. =============================== Author ===============================
  367. ======================================================================
  368.  
  369.                                Olaf Barthel
  370.                              Brabeckstrasse 35
  371.                             D-3000 Hannover 71
  372.  
  373.                         Federal Republic of Germany
  374.  
  375.    I  may  also  answer questions asked via electronic mail.  My email
  376. addresses are:
  377.  
  378.                    Z-Netz: O.BARTHEL@A-LINK-H
  379.                    Usenet: o.barthel@a-link-h.comlink.de
  380.                            olsen@sourcery.mxm.sub.org
  381.  
  382. ============ Revision history (most recent change first) =============
  383. ======================================================================
  384. 37.1    Recompiled for use with Kickstart 2.0.
  385.  
  386. 36.14   This  release  fixes  a  potential bug in the GetToken routine
  387.         (Stefan Sticht discovered it).  Tokens may be separated by any
  388.         blank  character  (such as tabs, spaces, newlines, etc.).  The
  389.         Rexx   clip   list  can  be  scanned  using  a  new  function:
  390.         GetRexxClip.   Due  to a bug to be found in the 'C' compiler I
  391.         had  to  remove  the inline library calls and to turn off code
  392.         optimization  in  the  LibMain  module.   Code size climbed by
  393.         about 400 bytes.
  394.  
  395. 35.13   Added    new    functions    (GetRexxMsg,    SendRexxMsg   and
  396.         GetRexxString)   which  I  found  missing  for  the  last  few
  397.         revisions.   I  also  rewrote parts of the library code to get
  398.         rid of those nasty 'goto' statements.
  399.  
  400. 34.12   The  library  can  be recompiled using 16 bit integers now.  I
  401.         don't  know  if  anybody  profits  from  this feature but it's
  402.         included  anyway.   By  the  way:   code  size went up to 2912
  403.         bytes.
  404.  
  405. 34.11   The library  went through  the third major rewrite, along with
  406.         some  more cleanups (nobody told me that the NULL-function has
  407.         to   be  supported)  assembly  language  string-routines  were
  408.         introduced to reduce the amount of support-library code.  Code
  409.         size dropped to 2840 bytes.
  410.  
  411. 34.10   Some  more  cleanups  in  RexxStrCmp  and  other routines were
  412.         really  necessary.   As  a  result,  code size went up to 2900
  413.         bytes.
  414.  
  415. 34.9    Added  more sanity checks in the Rexx Host creation/management
  416.         procedure.  An extended MsgPort structure with additional type
  417.         data  holds  the interface now.  Library code and data are now
  418.         much  more  compact than in the previous releases (I spent two
  419.         additional days debugging the code). Library  size  should  be
  420.         2792 bytes now.
  421.  
  422. 34.8    ANSIfication,   more   cleanups,   added  RexxStrCmp,  rewrote
  423.         CreateRexxHost/DeleteRexxHost  to become shorter, made library
  424.         use #pragma calls rather than  to  rely  on  the  rexxglue.asm
  425.         output file. Code size went down to about 2764 bytes (original
  426.         size: 3512 bytes).
  427.  
  428. 34.7    Ported   to  Aztec  'C'  5.0,  the  strange  library  creation
  429.         procedure  consumed lots of time (in which the author consumed
  430.         lots of cups of coffee).
  431.  
  432. 1.6     Initial creation using MkLib & elib.
  433.